package com.network.util.snmp4j;

import java.util.HashMap;
import java.util.LinkedHashMap;

public final class SnmpGetResultSet
{
	private HashMap<String, Integer> oidIndexMap = new HashMap<String, Integer>();
	private LinkedHashMap<String, String[]> queryResult = new LinkedHashMap<String, String[]>();
	private String keySet[] = null;
	private int rowIndex = -1;

	public final String[] getKeySet()
	{
		return keySet;
	}

	public final void head()
	{
		rowIndex = -1;
	}

	public final boolean next()
	{
		boolean rtnCode = false;
		rowIndex++;
		if (rowIndex < getRowCount())
		{
			rtnCode = true;
		}
		return rtnCode;
	}

	public final String getValue(String oid)
	{
		return getValue(oid, rowIndex);
	}

	public final String getValue(String oid, int row)
	{
		Integer index = oidIndexMap.get(oid);
		if (index == null)
		{
			return null;
		}
		String strValue = "";
		try
		{
			strValue = queryResult.get(keySet[row])[index];
		}
		catch (RuntimeException e)
		{
			System.out.println(e.getLocalizedMessage());
			e.printStackTrace();
		}
		return strValue;
	}

	public final int getRowCount()
	{
		return queryResult.size();
	}

	public final String getOidIndex(int row)
	{
		String oidIndex = "";
		if (row >= 0 && row < keySet.length)
		{
			oidIndex = keySet[row];
		}
		return oidIndex;
	}

	public final void setOidIndexMap(HashMap<String, Integer> oidIndex)
	{
		this.oidIndexMap = oidIndex;
	}

	public final void setQueryResult(LinkedHashMap<String, String[]> queryResult)
	{
		this.queryResult = queryResult;
		int rowNum = this.queryResult.keySet().size();
		keySet = new String[rowNum];
		rowNum = 0;
		for (String oidIndexTemp : this.queryResult.keySet())
		{
			keySet[rowNum++] = oidIndexTemp;
		}
	}

	public final HashMap<String, Integer> getOidIndexMap()
	{
		return this.oidIndexMap;
	}

	public final LinkedHashMap<String, String[]> getQueryResult()
	{
		return this.queryResult;
	}
}
